package cn.edu.thu.tsquality.core.algorithm.linear.repair;


import cn.edu.thu.tsquality.adaptor.single.SingleAdaptor;
import cn.edu.thu.tsquality.core.common.algorithm.IAlgorithm;
import cn.edu.thu.tsquality.core.common.util.ArgumentsHelper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class SingleMain
{
    public static void main(String[] args) throws IOException
    {

        System.out.println("LinearRepair");
        System.out.println("args length="+args.length);
        for(int i = 0; i < args.length; i++)
            System.out.println("arg[" + i + "] = " + args[i]);

        String inputPath = args[0];
        String outputPath = args[1];

        List<String> usedAttrs = null;

        try
        {
            if(args.length == 3)
            {
                String[] arguments = ArgumentsHelper.getArguments(args[2]);

                int argIndex = 0;

                if (arguments.length != 0 && arguments.length != 1)
                    throw new IllegalArgumentException("argument error, expected 0/1 argument, got " + args.length);

                // 如果没有参数，那么以整张表作为输入，进行不精确的修复
                // 如果参数有1个，那么参数是选择列名称，进行不完整的修复
                if (arguments.length == 1)
                {
                    String[] attrs = ArgumentsHelper.getValues(arguments[argIndex++]);
                    if (attrs.length != 1)
                        throw new IllegalArgumentException("attrs error, expected 1 attr, got " + attrs.length);

                    usedAttrs = new ArrayList<>(Arrays.asList(attrs));
                }
            }
            IAlgorithm algorithm = new LinearRepair();
            SingleAdaptor adaptor = new SingleAdaptor();
            adaptor.setAlgorithm(algorithm);
            adaptor.run(inputPath, outputPath, usedAttrs);
        }
        catch (Exception e)
        {
            System.out.println("Catch Exception: "+e.toString());
            throw e;
        }
    }
}


